﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dami;
public partial class admin_Modules_hotro_AddNew : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
        this.btnCancel.Attributes.Add("onclick","return ClearAll()");

        if (!this.IsPostBack) {
            ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
        }
    }

   

    private void AddNew() {
        String strMess = "";
        int flag = -1;  
            try
            {
                WebData data = new WebData();
                clsFileUpLoad files = new clsFileUpLoad();
                String pathImage = "";
                pathImage = files.FileSaveImage("upload/image",this.FileUpload1);
                DataLibrary.tbl_Hotro item = new DataLibrary.tbl_Hotro();
                item.Id = 1;
                item.Image = pathImage;
                item.IsActive = 1;
                item.OrderId = Convert.ToInt32(txtorderId.Text);
                item.Title = txtTitle.Text;
                item.Url = txtUrl.Text;
                item.Description = txtDescription.Text;
                item.IdTable = cbbidCat.SelectedValue.ToString();
                item.IdTable = item.IdTable.Replace("0", "");
                flag=data.tbl_Hotros.InsertOnSubmit(item);
            }
            catch (Exception err)
            {
                strMess = Message.Insert_err + "! vì lỗi " + err.Message.ToString();
            }
            if (flag > -1) {
                Response.Redirect(ViewState["URLReferrer"].ToString());
            }
        else
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Err", "alert('" + strMess + "');", true);

    }

    protected void btnAddNew_Click(object sender, EventArgs e)
    {
            AddNew();
    }
}